package com.gzgxzc.czh.administrator.smoke.Activity;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.gzgxzc.czh.administrator.smoke.R;
import com.gzgxzc.czh.administrator.smoke.TianUiL.City;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import java.net.HttpURLConnection;
import java.util.List;

import okhttp3.Call;
import okhttp3.Response;

public class Weather_activity extends AppCompatActivity {
    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;
    private TextView textView5;
    private TextView textView6;
    private TextView textView;
    private ImageView iv_tupian1;
    private ImageView iv_tuoian2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weather_activity);
        textView = (TextView) findViewById(R.id.texty);
        textView1 = (TextView) findViewById(R.id.texty1);
        textView2 = (TextView) findViewById(R.id.texty2);
        textView3 = (TextView) findViewById(R.id.texty3);
        textView4 = (TextView) findViewById(R.id.texty4);
        textView5 = (TextView) findViewById(R.id.texty5);
        textView6 = (TextView) findViewById(R.id.texty6);
        iv_tupian1 = (ImageView) findViewById(R.id.iv_tupian1);
        iv_tuoian2 = (ImageView) findViewById(R.id.iv_tupian2);

        OkGo.get("http://api.map.baidu.com/telematics/v3/weather?location=贵阳&output=json&ak=FA09d4649e228793fd44c9b1c1575e0d")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        Gson  gson = new Gson();
                        City city = gson.fromJson(s,City.class);
                        List<City.ResultsBean> citt = city.getResults();
                        textView.setText(citt.get(0).getCurrentCity());
                        textView1.setText(citt.get(0).getPm25());
                        List<City.ResultsBean.IndexBean> ci = citt.get(0).getIndex();
                        textView2.setText(ci.get(0).getDes()+"\n"+ci.get(0).getTipt()+"\n"+ci.get(0).getTitle()+"\n"+ci.get(0).getZs());
                        List<City.ResultsBean.WeatherDataBean> cc = citt.get(0).getWeather_data();
                        textView3.setText(cc.get(0).getDate());
                        textView4.setText(cc.get(0).getTemperature());
                        textView5.setText(cc.get(0).getWeather());
                        textView6.setText(cc.get(0).getWind());

                        String a = cc.get(0).getDayPictureUrl();
                        String b = cc.get(0).getNightPictureUrl();
                       iv_tupian1.setImageURI(Uri.parse(b));


                    }
                });

    }
}
